<?php
/**
* @file $Id: UnfilledRequests.php 161 2006-09-07 06:21:17Z doritojones $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

if($_REQUEST['modname']=='Scheduling/UnfilledRequests.php')
	DrawHeader(ProgramTitle());

$extra['SELECT'] = ',c.TITLE||\' - \'||sr.COURSE_WEIGHT AS COURSE,sr.SUBJECT_ID,sr.COURSE_ID,sr.COURSE_WEIGHT,sr.WITH_TEACHER_ID,sr.NOT_TEACHER_ID,sr.WITH_PERIOD_ID,sr.NOT_PERIOD_ID,(SELECT COALESCE(sum(COALESCE(cp.TOTAL_SEATS,0)-COALESCE(cp.FILLED_SEATS,0)),0) AS AVAILABLE_SEATS FROM COURSE_PERIODS cp WHERE cp.COURSE_ID=sr.COURSE_ID AND cp.COURSE_WEIGHT=sr.COURSE_WEIGHT AND (cp.GENDER_RESTRICTION=\'N\' OR cp.GENDER_RESTRICTION=substring(s.CUSTOM_200000000,1,1)) AND (sr.WITH_TEACHER_ID IS NULL OR sr.WITH_TEACHER_ID=\'\' OR sr.WITH_TEACHER_ID=cp.TEACHER_ID) AND (sr.NOT_TEACHER_ID IS NULL OR sr.NOT_TEACHER_ID=\'\' OR sr.NOT_TEACHER_ID!=cp.TEACHER_ID) AND (sr.WITH_PERIOD_ID IS NULL OR sr.WITH_PERIOD_ID=\'\' OR sr.WITH_PERIOD_ID=cp.PERIOD_ID) AND (sr.NOT_PERIOD_ID IS NULL OR sr.NOT_PERIOD_ID=\'\' OR sr.NOT_PERIOD_ID!=cp.PERIOD_ID)) AS AVAILABLE_SEATS,(SELECT count(*) AS SECTIONS FROM COURSE_PERIODS cp WHERE cp.COURSE_ID=sr.COURSE_ID AND cp.COURSE_WEIGHT=sr.COURSE_WEIGHT AND (cp.GENDER_RESTRICTION=\'N\' OR cp.GENDER_RESTRICTION=substring(s.CUSTOM_200000000,1,1)) AND (sr.WITH_TEACHER_ID IS NULL OR sr.WITH_TEACHER_ID=\'\' OR sr.WITH_TEACHER_ID=cp.TEACHER_ID) AND (sr.NOT_TEACHER_ID IS NULL OR sr.NOT_TEACHER_ID=\'\' OR sr.NOT_TEACHER_ID!=cp.TEACHER_ID) AND (sr.WITH_PERIOD_ID IS NULL OR sr.WITH_PERIOD_ID=\'\' OR sr.WITH_PERIOD_ID=cp.PERIOD_ID) AND (sr.NOT_PERIOD_ID IS NULL OR sr.NOT_PERIOD_ID=\'\' OR sr.NOT_PERIOD_ID!=cp.PERIOD_ID)) AS SECTIONS ';
$extra['FROM'] = ',SCHEDULE_REQUESTS sr,COURSES c';
$extra['WHERE'] = ' AND sr.STUDENT_ID=ssm.STUDENT_ID AND sr.SYEAR=ssm.SYEAR AND sr.SCHOOL_ID=ssm.SCHOOL_ID AND sr.COURSE_ID=c.COURSE_ID AND NOT EXISTS (SELECT \'\' FROM SCHEDULE s WHERE s.STUDENT_ID=sr.STUDENT_ID AND s.COURSE_ID=sr.COURSE_ID AND s.COURSE_WEIGHT=sr.COURSE_WEIGHT)';
$extra['functions'] = array('WITH_TEACHER_ID'=>'_makeTeacher','WITH_PERIOD_ID'=>'_makePeriod');
$extra['columns_after'] = array('COURSE'=>_('Request'),'AVAILABLE_SEATS'=>_('Available Seats'),'SECTIONS'=>_('Sections'),'WITH_TEACHER_ID'=>_('Teacher'),'WITH_PERIOD_ID'=>_('Period'));
$extra['singular'] = _('Unscheduled Request');
$extra['plural'] = _('Unscheduled Requests');
if(!$extra['link']['FULL_NAME'])
{
	$extra['link']['FULL_NAME']['link'] = 'Modules.php?modname=Scheduling/Requests.php';
	$extra['link']['FULL_NAME']['variables']['student_id'] = 'STUDENT_ID';
}
$extra['new'] = true;
$extra['Redirect'] = false;

if($_REQUEST['modname']=='Scheduling/UnfilledRequests.php')
	Search('student_id',$extra);
else
{
	$extra['functions']['COURSE'] = '_makeCourse';
	$old_student_list = $_SESSION['student_list'];
	$RET = GetStuList($extra);
	$_SESSION['student_list'] = $old_student_list;

	if(count($RET))
	{
		$columns = array('COURSE'=>_('Request'),'AVAILABLE_SEATS'=>_('Available Seats'),'SECTIONS'=>_('Sections'),'WITH_TEACHER_ID'=>_('Teacher'),'WITH_PERIOD_ID'=>_('Period'));
		ListOutput($RET,$columns,_('Unscheduled Request'),_('Unscheduled Requests'),$extra['link']);
	}
}

function _makeTeacher($value,$column)
{	global $THIS_RET;

	return ($value!=''?_('With').': '.GetTeacher($value).'<BR>':'').($THIS_RET['NOT_TEACHER_ID']!=''?_('Without').': '.GetTeacher($THIS_RET['NOT_TEACHER_ID']):'');
}

function _makePeriod($value,$column)
{	global $THIS_RET;

	return ($value!=''?_('On').': '.GetPeriod($value).'<BR>':'').($THIS_RET['NOT_PERIOD_ID']!=''?_('Not on').': '.GetPeriod($THIS_RET['NOT_PERIOD_ID']):'');
}

function _makeCourse($value,$column)
{
	return button('add').$value;
}
?>